package com.jian.sys.common;


import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/**
 * 获取spring IOC容器
 */
@Component
public class SpringUtils implements ApplicationContextAware {
    //获取上下文对象
    private static ApplicationContext applicationContext;


    @Override
    public void setApplicationContext(ApplicationContext alc) throws BeansException {
        applicationContext=alc;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public  static <T> T getBean(Class<T> cls){
        return applicationContext.getBean(cls);
    }
}
